<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript">
    require([ "dojo/_base/array", "dojo/_base/xhr", "dojo/request", "dojo/topic", "dojo/json"],
            function(array, xhr, request, topic, JSON) {
                var deletItemsCount = 0;
                conferenceRestForm = function(formId) {
                    dijit.byId(formId).reset();
                    if (formId.indexOf('UFD') != -1) {
                        var rowid = jQuery("#conferenceGird").jqGrid('getGridParam', 'selrow');
                        var conference = jQuery("#conferenceGird").jqGrid('getRowData', rowid);
                        dijit.byId('conferenceUFD').setValues(conference);
                    }
                };
                topic.subscribe("conference/insertOrUpdate", conferenceRestForm);
                var syncDB = function(url, jsonData) {
                    request.post(url, {
                        data : jsonData,
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        topic.publish("notifyMsgTopic", {
                            message : response,
                            type : "message",
                            duration : 1000
                        });
                        var currentPage = jQuery('#conferenceGird').jqGrid('getGridParam', 'page');
                        var pageSize = jQuery('#conferenceGird').jqGrid('getGridParam', 'rowNum');
                        var totalCount = jQuery('#conferenceGird').jqGrid('getGridParam', 'records') - deletItemsCount;
                        var totalPages = Math.ceil(totalCount / pageSize);
                        jQuery("#conferenceGird").jqGrid('setGridParam', {
                            page : currentPage > totalPages ? totalPages : currentPage
                        }).trigger("reloadGrid");
                    }, function(error) {
                        alert(error);
                    });
                };
                conferenceSubmitForm = function(formId, type) {
                    var url = "conference/insert";
                    if (type == 'u') {
                        url = "conference/update";
                    }
                    var form = dijit.byId(formId);
                    if (form.isValid()) {
                        var json = JSON.stringify(form.getValues());
                        syncDB(url, json);
                        form.hide();
                        topic.publish("conference/insertOrUpdate", formId);
                    } else {
                        form.validate();
                    }
                };
                conferenceDelete = function() {
                    var ids = jQuery("#conferenceGird").jqGrid('getGridParam', 'selarrrow') || [];
                    deletItemsCount = ids.length;
                    if (ids.length > 0) {
                        if (confirm('确认删除所选定的项？')) {
                            var conference = {};
                            conference.id = '';
                            array.forEach(ids, function(entry, i) {
                                conference.id += entry + ",";
                            });
                            syncDB("conference/delete", JSON.stringify(conference));
                        }
                    } else {
                        alert('请选择至少一条数据!');
                    }
                };
                conferenceQuery = function(formId) {
                    var conference = dijit.byId(formId).getValues();
                    jQuery("#conferenceGird").jqGrid('setGridParam', {
                        postData : conference,
                        mtype : "post"
                    }).trigger('reloadGrid');
                };
                //显示审核页面
                showDetail=function(formid,rowid){
                    conferenceCheck = jQuery("#conferenceGird").jqGrid('getRowData', rowid);
                    var url="conference/selectAttachment/"+conferenceCheck["confid"];
                    request.post(url, {
                        headers : {
                            'Content-Type' : "application/json; charset=utf-8"
                        },
                        timeout : 30000
                    }).then(function(response) {
                        var attachs = JSON.parse(response);
                        var attacharea;
                        if(formid=="conferenceCheckDetail"){
                            attacharea =dojo.byId("ConferenceAttachDownLoadDetail");
                        }else{
                            attacharea =dojo.byId("ConferenceAttachDownLoad");
                        }
                        var download='';
                        array.forEach(attachs, function(entry, i) {
                            link="<a href='attachment/download?fileid="+entry.fileid+"' style='text-decoration: none;'/>"+entry.filename+"</a>&nbsp;&nbsp;"
                            download+=link;
                        });
                        attacharea.innerHTML=download;
                    }, function(error) {
                        alert(error);
                    });
                    dijit.byId(formid).setValues(conferenceCheck);
                    dijit.byId(formid).show();
                };
                //审核
                Check = function(formid,flag){
                    var unis = {
                            "否" : '0',
                            "是" : '1'
                            };
                    var unimportlevel = {
                            "普通" : '1',
                            "重要" : '2',
                            "非常重要" : '3'
                            };
                    var form=dijit.byId(formid);
                    
                    var json = {
                            confid : form.value["confid"],
                            checkstatus : flag,
                            importlevel : unimportlevel[form.value["importlevel"]],
                            ismobile : unis[form.value["ismobile"]],
                            isemail : unis[form.value["isemail"]],
                            feebudget : form.value["feebudget"],
                            status: 1
                        };
                    syncDB("conference/update", JSON.stringify(json));
                    form.hide();
                };
            });
    require(["dojo/_base/array", "dojo/request", "dojo/ready", "dojo/store/JsonRest", "dojo/json", "dijit/form/CheckBox", "dijit/form/Select" ], 
            function(array,request,ready, JsonRest, JSON,CheckBox, Select) {
        ready(function(){
            request.post("conference/selectBoardRoom", {
                headers : {
                    'Content-Type' : "application/json; charset=utf-8"
                },
                timeout : 30000
            }).then(function(response) {
                var ops=JSON.parse(response);
                ops.push({label : "全部", value : "all", selected : "true"});
                new Select({
                    name : "roomid",
                    style : "width: 99%",
                    options: ops
                }, "SearchCheckRoomId").startup();
                console.log(dijit.byId("SearchCheckRoomName").getValue());
            }, function(error) {
                alert(error);
            });
            request.post("conference/selectBoardType", {
                headers : {
                    'Content-Type' : "application/json; charset=utf-8"
                },
                timeout : 30000
            }).then(function(response) {
                var ops=JSON.parse(response);
                ops.push({label : "全部", value : "all", selected : "true"});
                new Select({
                    name : "typeid",
                    style : "width: 99%",
                    options: ops
                }, "SearchCheckTypeId").startup();
            }, function(error) {
                alert(error);
            });
        }); 
    });
</script>
<div data-dojo-type="dijit/Dialog" id="conferenceCheckUFD" title="审批">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text" name="confid" style="display: none;">
    <table border="0">
        <tr>
            <td><label for="conftopic">会议议题: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="conftopic"/>
            </td>
            <td><label for="roomname">会议室: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="roomname"/>
            </td>
        </tr>
        <tr>
            <td><label for="typename">会议类型: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="typename"/>
            </td>
            <td><label for="feebudget">费用预算: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="feebudget"/>
            </td>
        </tr>
        <tr>
            <td><label for="ismobile">短信通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="ismobile"/>
            </td>
            <td><label for="isemail">邮件通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="isemail"/>
            </td>
            <td><label for="importlevel">重要级别: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="importlevel"/>
            </td>
        </tr>
        <tr>
            <td><label for="confcontent">会议内容: </label></td>
            <td colspan="5">
                <div data-dojo-type="dijit/Editor" data-dojo-props="plugins:[], height: 100" name="confcontent"/>
            </td>
        </tr>
        <tr>
            <td><label for="comperename">主持人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="comperename"/>
            </td>
            <td><label for="recordername">记录人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="recordername"/>
            </td>
            <td><label for="attendusersname">参加人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="attendusersname"/>
            </td>
        </tr>
        <tr>
            <td><label for="starttime">开始时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="starttime"/>
            </td>
            <td><label for="endtime">结束时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="endtime"/>
            </td>
            <td><label for="checkname">审批人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="checkname"/>
            </td>
        </tr>
        <tr>
            <td><label>附件: </label></td>
            <td colspan="5" id="ConferenceAttachDownLoad">
            </td>
        </tr>
    </table>
  </div>
  <div class="dijitDialogPaneActionBar">
    <button data-dojo-type="dijit/form/Button" type="button" onclick="Check('conferenceCheckUFD','1')">审核通过</button>
    <button data-dojo-type="dijit/form/Button" type="button" onclick="Check('conferenceCheckUFD','0')">退回</button>
  </div>
</div>
<div data-dojo-type="dijit/Dialog" id="conferenceCheckDetail" title="详情">
  <div class="dijitDialogPaneContentArea">
    <input data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required: true, readOnly: true" type="text" name="confid" style="display: none;">
    <table border="0">
        <tr>
            <td><label for="conftopic">会议议题: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="conftopic"/>
            </td>
            <td><label for="roomname">会议室: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="roomname"/>
            </td>
        </tr>
        <tr>
            <td><label for="typename">会议类型: </label></td>
            <td colspan="3">
                <input style="width: 99.7%" data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="typename"/>
            </td>
            <td><label for="feebudget">费用预算: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="feebudget"/>
            </td>
        </tr>
        <tr>
            <td><label for="ismobile">短信通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="ismobile"/>
            </td>
            <td><label for="isemail">邮件通知: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="isemail"/>
            </td>
            <td><label for="importlevel">重要级别: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="importlevel"/>
            </td>
        </tr>
        <tr>
            <td><label for="confcontent">会议内容: </label></td>
            <td colspan="5">
                <div data-dojo-type="dijit/Editor" data-dojo-props="plugins:[], height: 100" name="confcontent"/>
            </td>
        </tr>
        <tr>
            <td><label for="comperename">主持人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="comperename"/>
            </td>
            <td><label for="recordername">记录人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="recordername"/>
            </td>
            <td><label for="attendusersname">参加人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="attendusersname"/>
            </td>
        </tr>
        <tr>
            <td><label for="starttime">开始时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="starttime"/>
            </td>
            <td><label for="endtime">结束时间: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="endtime"/>
            </td>
            <td><label for="checkname">审批人: </label></td>
            <td>
                <input data-dojo-type="dijit/form/TextBox" data-dojo-props="readOnly: true" name="checkname"/>
            </td>
        </tr>
        <tr>
            <td><label>附件: </label></td>
            <td colspan="5" id="ConferenceAttachDownLoadDetail">
            </td>
        </tr>
    </table>
  </div>
</div>
<fieldset>
  <legend>&nbsp;&nbsp;信息选项&nbsp;&nbsp;</legend>
  <form id="querycheckconferenceForm" data-dojo-type="dijit/form/Form" method="post">
    <div style="margin-left: 5px;">
      <table>
        <tr>
          <td><label for="conftopic">会议议题: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="conftopic"></td>
          <td><label for="typeid">会议类型: </label></td>
          <td>
              <input name="typeid" id="SearchCheckTypeId" />
          </td>
          <td><label for="confcontent">会议内容: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="confcontent"></td>
        </tr>
        <tr>
          <td><label for="roomid">会议室: </label></td>
          <td>
              <input id="SearchCheckRoomId" />
          </td>
          <td><label for="starttime">开始时间: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="starttime" id="SearchCheckStartTime" onClick="WdatePicker({maxDate:'#F{$dp.$D(\'SearchCheckEndTime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss'})"></td>
          <td><label for="endtime">结束时间: </label></td>
          <td><input data-dojo-type="dijit/form/TextBox" data-dojo-props="trim: true" type="text" name="endtime" id="SearchCheckEndTime" onClick="WdatePicker({minDate:'#F{$dp.$D(\'SearchCheckStartTime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss'})"></td>
        </tr>
      </table>
    </div>
  </form>
  <div style="padding: 5px;">
    <button id="conferenceDeleteBtn" data-dojo-type="dijit/form/Button" type="button" label="删除" onclick="conferenceDelete();"></button>
      <script type="dojo/method" event="onClick" args="evt">
        var ids = jQuery("#conferenceGird").jqGrid('getGridParam', 'selarrrow') || [];
        if (ids.length != 1) {
          alert('每次只能修改一条数据!');
        }else{
          var conference = jQuery("#conferenceGird").jqGrid('getRowData', ids[0]);
          dijit.byId('conferenceUFD').setValues(conference);
          dijit.byId('conferenceUFD').show();
        }
      </script>
    </button>
    <button id="conferenceQueryBtn" data-dojo-type="dijit/form/Button" type="button" label="查询"
      onclick="conferenceQuery('querycheckconferenceForm');"></button>
  </div>
</fieldset>
<div id="gird">
  <table id="conferenceGird"></table>
  <div id="conferenceToolbar"></div>
</div>
<script type="text/javascript">
    var is={
            '0': "否",
            '1': "是"
            };
    var importlevel={
            '1': "普通",
            '2': "重要",
            '3': "非常重要"
            };
    jQuery("#conferenceGird").jqGrid({
        //当参数为y时只查询审批人为当前用户的记录
        url : 'conference/queryAsList/y',
        datatype : "json",
        autowidth : true,
        rownumbers : true,
        height : 'auto',
        colNames : [
          '会议ID',
          '会议议题',
          '会议性质',
          '重要级别1=普通、2=重要、3=非常重要',
          '费用预算',
          '会议主持人',
          '主持人(允许多人，用,分开)',
          '记录人(允许多人，用,分开)',
          '会议记录人',
          '参加人员列表（USERID）',
          '参与人员姓名列表',
          '状态0=暂存、1=发布',
          '邮件通知',
          '短信通知',
          '开始时间',
          '结束时间',
          '会议室ID',
          '会议类型ID',
          '会议室',
          '会议地点',
          '会议内容',
          '创建时间',
          '发送时间',
          '审批意见，备注',
          '审批人USERID',
          '审批人姓名',
          '类型名称',
          '审批结果'          
        ],
        colModel : [ 
        {
          name : 'confid',
          index : 'confid',
          width : 60,
          key : true,
          hidden : true,
          align : 'center'
        },
        {
          name : 'conftopic',
          index : 'conftopic'
        },
        {
          name : 'confproperty',
          hidden : true,
          index : 'confproperty'
        },
        {
          name : 'importlevel',
          hidden : true,
          index : 'importlevel'
        },
        {
          name : 'feebudget',
          hidden : true,
          index : 'feebudget'
        },
        {
          name : 'comperename',
          index : 'comperename'
        },
        {
          name : 'compere',
          hidden : true,
          index : 'compere'
        },
        {
          name : 'recorder',
          hidden : true,
          index : 'recorder'
        },
        {
          name : 'recordername',
          hidden : true,
          index : 'recordername'
        },
        {
          name : 'attendusers',
          hidden : true,
          index : 'attendusers'
        },
        {
          name : 'attendusersname',
          hidden : true,
          index : 'attendusersname'
        },
        {
          name : 'status',
          hidden : true,
          index : 'status'
        },
        {
          name : 'isemail',
          hidden : true,
          index : 'isemail'
        },
        {
          name : 'ismobile',
          hidden : true,
          index : 'ismobile'
        },
        {
          name : 'starttime',
          index : 'starttime'
        },
        {
          name : 'endtime',
          index : 'endtime'
        },
        {
          name : 'roomid',
          hidden : true,
          index : 'roomid'
        },
        {
          name : 'typeid',
          hidden : true,
          index : 'typeid'
        },
        {
          name : 'roomname',
          align : 'center',
          index : 'roomname'
        },
        {
          name : 'roomlocation',
          hidden : true,
          index : 'roomlocation'
        },
        {
          name : 'confcontent',
          hidden : true,
          index : 'confcontent'
        },
        {
          name : 'createtime',
          hidden : true,
          index : 'createtime'
        },
        {
          name : 'sendtime',
          hidden : true,
          index : 'sendtime'
        },
        {
          name : 'checkreason',
          hidden : true,
          index : 'checkreason'
        },
        {
          name : 'checkuserid',
          hidden : true,
          index : 'checkuserid'
        },
        {
          name : 'checkname',
          hidden : true,
          index : 'checkname'
        },
        {
            name : 'typename',
            align : 'center',
            index : 'typename'
        },
        {
          name : 'checkstatus',
          width : 120,
          align : 'center',
          index : 'checkstatus'
        }
        ],
        rowNum : 15,
        rowList : [ 15, 20, 25, 30 ],
        pager : '#conferenceToolbar',
        // sortname : 'username',
        recordpos : 'right',
        viewrecords : true,
        sortorder : "desc",
        jsonReader : {
            repeatitems : false
        },
        
        gridComplete : function() {
            var ids = jQuery("#conferenceGird").jqGrid('getDataIDs');
            for ( var i = 0; i < ids.length; i++) {
                var cl = ids[i];
                var carcheck = jQuery("#conferenceGird").jqGrid('getRowData', cl);
                var unfinish="<a href='javascript:void(0);' onclick=\"showDetail('conferenceCheckUFD'"+",'"+cl+"')\">未审批</a>";
                var finish="<a href='javascript:void(0);' onclick=\"showDetail('conferenceCheckDetail'"+",'"+cl+"')\">通过审批(查看详情)</a>";
                var back="<a href='javascript:void(0);' onclick=\"showDetail('conferenceCheckDetail'"+",'"+cl+"')\">未通过审批(查看详情)</a>";
                var mystatus = carcheck['checkstatus'] == '2' ? unfinish : (carcheck['checkstatus'] == '1' ? finish : back);
                var myismobile= is[carcheck["ismobile"]];
                var myisemail= is[carcheck["isemail"]];
                var myimportlevel= importlevel[carcheck["importlevel"]];
                jQuery("#conferenceGird").jqGrid('setRowData', cl, {
                    checkstatus: mystatus,
                    isemail: myisemail,
                    ismobile: myismobile,
                    importlevel: myimportlevel
                });
            }
        },
        multiselect : true,
        shrinkToFit : false,
        caption : "会议申请表列表"
    });
    jQuery("#conferenceGird").jqGrid('navGrid', '#conferenceToolbar', {
        edit : false,
        add : false,
        del : false,
        search : false,
        refresh : true
    });
</script>
